package com.smedi.ismedi.constructionproject.core.port.adapter.service.impl;

import com.smedi.ismedi.constructionproject.core.domain.dto.FileQuery;
import com.smedi.ismedi.constructionproject.core.infrastructure.constant.CustomError;
import com.smedi.ismedi.constructionproject.core.port.adapter.restful.convert.AdapterConverter;
import com.smedi.ismedi.constructionproject.core.port.adapter.service.FileRemoteService;
import com.smedi.ismedi.file.dto.response.FileInfoResponse;
import com.smedi.ismedi.file.feign.RemoteFileFeignApi;
import com.smedi.ismedi.web.starter.common.ResponseData;
import com.smedi.ismedi.web.starter.exception.LogicException;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther Cookie
 * @date 2022/7/20
 */
@Service
@Slf4j
@AllArgsConstructor
public class FileRemoteServiceImpl implements FileRemoteService {

    private final RemoteFileFeignApi remoteFileFeignApi;

    @Override
    public FileInfoResponse getFileInfoOne(FileQuery fileQuery) {
        return null;
    }

    @Override
    public List<FileInfoResponse> getFileInfoList(FileQuery fileQuery) {
        ResponseData<List<FileInfoResponse>> responseData = remoteFileFeignApi.getFileList(fileQuery.getSignKeys());
        if (!responseData.isSuccess()) {
            throw LogicException.raise(CustomError.CALL_REMOTE_API_ERROR, responseData.getApplication(), String.valueOf(responseData.getErrorMsg()));
        }
        return responseData.getData();
    }
}
